﻿using System;
using System.Collections.Generic;
using System.Windows.Media;
using MvvmFx.Common.ViewModels;


namespace MvvmFx.Samples.HowTos.ViewModelHelper.ViewModels
{
    public class SampleItemViewModel : ViewModelBase
    {
        #region instance variables

        private string _name;
        private int _age;
        private Color _color;
        private DateTime _lastSelected;

        #endregion


        #region constructors

        public SampleItemViewModel()
        {
        }

        public SampleItemViewModel(string name, int age, Color color)
        {
            _name = name;
            _age = age;
            _color = color;
        }

        #endregion


        #region properties

        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
                OnPropertyChanged("Name");
            }
        }

        public int Age
        {
            get { return _age; }
            set
            {
                _age = value;
                OnPropertyChanged("Age");
            }
        }

        public Color Color
        {
            get { return _color; }
            set
            {
                _color = value;
                OnPropertyChanged("Color");
            }
        }

        public DateTime LastSelected
        {
            get { return _lastSelected; }
            set
            {
                _lastSelected = value;
                OnPropertyChanged("LastSelected");
            }
        }

        #endregion


        #region public methods

        public static IEnumerable<SampleItemViewModel> Create(int count)
        {
            // use randomizer to generate random data
            Random randomizer = new Random();

            // create samples
            for (int i = 0; i < count; ++i)
            {
                // create new sample data
                SampleItemViewModel sample = new SampleItemViewModel()
                {
                    Name = string.Format("Sample {0:00}", i + 1),
                    Age = randomizer.Next(5, 60),
                    Color = Color.FromArgb(255, (byte)randomizer.Next(180),
                        (byte)randomizer.Next(180), (byte)randomizer.Next(180))
                };

                // and add to list of samples
                yield return sample;
            }
        }

        #endregion

    }  // class SampleItemViewModel 

}  // namespace MvvmFx.Samples.HowTos.ViewModelHelper.ViewModels
